﻿using ASmile.Com;
using ASmile.Win;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ASmile.Setter
{
    class Startup
    {
        static FrmLoading LoadingForm;

        public static void Run()
        {
            LogHelper.LogObj.Info("app run");
            //本地数据库访问
            ConfigCom.Set(new ConfigCom
            {
                CoreDbType = Config.Settings.DbType,
                CoreDbConnStr = Config.Settings.DbConnStr,
            });
            //Http访问
            Global.OnInitFinish += Global_OnInitFinish;
            var initTask = Global.Init();
            
            //TODO: 检查更新
            LoadingForm = new FrmLoading();
            LoadingForm.SetLoadingText("正在启动，请稍后。。。");
            LoadingForm.StartPosition = FormStartPosition.CenterScreen;
            LoadingForm.ShowDialog();

            if (new FrmLogin().ShowDialog() != DialogResult.OK)
            {
                Application.Exit();
            }
            else
            {
                Application.Run(new FrmMain());
            }
        }

        private static void Global_OnInitFinish()
        {
            LoadingForm.InvokeTask(LoadingForm.Close);
        }
    }
}